/*******************************************************************************
* Project: QSAR(Cute Software Architecture) 
*
* Copyright: Copyright(C) 2024 by YuetingBen, All Rights Reserved
*
* File name: Dem.c
*
* Brief: ;
*
* Author: Yueting.Ben
*
* Module: Dem
*
*******************************************************************************/

/** HEADER FILES **/
#include "Dem.h"


/** MACRO DEFINITION **/


/** TYPEDEF DEFINITION **/
typedef struct
{
    Dem_MonitorStatusType monitorStatus;
    Dem_UdsStatusByteType udsStatus;
    Dem_EventStatusType eventStatusOld;
    sint8 faultDetCounter;
}Dem_DtcInfoType;

/** LOCAL DATA DECLARATION **/
static Dem_DtcInfoType Dem_DtcInfo[DemConf_DemEventId_Max];


/** GLOBAL DATA DECLARATION **/


/** LOCAL FUNCTION DECLARATION **/


/** GLOBAL FUNCTION DECLARATION **/
void Dem_GetVersionInfo(
    Std_VersionInfoType* versionInfo
);

void Dem_Init(
    const Dem_ConfigType* ConfigPtr
);

Std_ReturnType Dem_ClearDTC(
    uint8 ClientId
);

Std_ReturnType Dem_SetEventStatus(
    Dem_EventIdType EventId,
    Dem_EventStatusType EventStatus
);

Std_ReturnType Dem_SetEventStatusWithMonitorData(
    Dem_EventIdType EventId,
    Dem_EventStatusType EventStatus,
    Dem_MonitorDataType monitorData0,
    Dem_MonitorDataType monitorData1
);

Std_ReturnType Dem_GetDTCStatusAvailabilityMask(
    uint8 ClientId,
    Dem_UdsStatusByteType* DTCStatusMask,
    Dem_DTCOriginType DTCOrigin
);

Std_ReturnType Dem_GetStatusOfDTC(
    uint8 ClientId,
    uint8* DTCStatus
);

Std_ReturnType Dem_SetDTCFilter(
    uint8 ClientId,
    uint8 DTCStatusMask,
    Dem_DTCFormatType DTCFormat,
    Dem_DTCOriginType DTCOrigin,
    boolean FilterWithSeverity,
    Dem_DTCSeverityType DTCSeverityMask,
    boolean FilterForFaultDetectionCounter
);

Std_ReturnType Dem_GetNumberOfFilteredDTC(
    uint8 ClientId,
    uint16* NumberOfFilteredDTC
);

Std_ReturnType Dem_GetNextFilteredDTC(
    uint8 ClientId,
    uint32* DTC,
    uint8* DTCStatus
);

Std_ReturnType Dem_GetNextFilteredDTCAndFDC(
    uint8 ClientId,
    uint32* DTC,
    sint8* DTCFaultDetectionCounter
);

Std_ReturnType Dem_SetDTCFilterByExtendedDataRecordNumber(
    uint8 ClientId,
    Dem_DTCFormatType DTCFormat,
    uint8 ExtendedDataRecordNumber
);

Std_ReturnType Dem_DisableDTCRecordUpdate(
    uint8 ClientId
);

Std_ReturnType Dem_EnableDTCRecordUpdate(
    uint8 ClientId
);

Std_ReturnType Dem_GetSizeOfExtendedDataRecordSelection(
    uint8 ClientId,
    uint32* SizeOfExtendedDataRecord
);

Std_ReturnType Dem_GetSizeOfFreezeFrameSelection(
    uint8 ClientId,
    uint32* SizeOfFreezeFrame
);

Std_ReturnType Dem_GetNextExtendedDataRecord(
    uint8 ClientId,
    uint8* DestBuffer,
    uint16* BufSize
);

Std_ReturnType Dem_GetNextFreezeFrameData(
    uint8 ClientId,
    uint8* DestBuffer,
    uint16* BufSize
);

Std_ReturnType Dem_SelectExtendedDataRecord(
    uint8 ClientId,
    uint8 ExtendedDataNumber
);

Std_ReturnType Dem_SelectFreezeFrameData(
    uint8 ClientId,
    uint8 RecordNumber
);

Std_ReturnType Dem_GetNumberOfFreezeFrameRecords(
    uint8 ClientId,
    uint16* NumberOfFilteredRecords
);

void Dem_MainFunction(
    void
);

/** LOCAL DATA **/


/** GLOBAL DATA **/


/** LOCAL FUNCTION **/


/** GLOBAL FUNCTION **/

/*******************************************************************************
* -Name            Dem_GetVersionInfo
* -Brief           Returns the version information of this module 
* -Details         None
* -Param[out]      versioninfo: Pointer to the version information of this module
* -Return          None          
*******************************************************************************/
void Dem_GetVersionInfo(
    Std_VersionInfoType* versionInfo
)
{
    versionInfo->vendorID = (uint16)YSAR_VENDOR_ID;
    versionInfo->moduleID = (uint8)DEM_MODULE_ID;
    versionInfo->sw_major_version = (uint8)DEM_SW_MAJOR_VERSION;
    versionInfo->sw_minor_version = (uint8)DEM_SW_MINOR_VERSION;
    versionInfo->sw_patch_version = (uint8)DEM_SW_PATCH_VERSION;
}

/*******************************************************************************
* -Name            Dem_Init
* -Brief           Initializes or reinitializes this module 
* -Details         None
* -Return          None          
*******************************************************************************/
void Dem_Init(
    const Dem_ConfigType* ConfigPtr
)
{
    
}


/*******************************************************************************
* -Name            Dem_ClearDTC
* -Brief           Clears single DTCs, as well as groups of DTCs 
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Return          None          
*******************************************************************************/
Std_ReturnType Dem_ClearDTC(
    uint8 ClientId
)
{
    
}


/*******************************************************************************
* -Name            Dem_SetEventStatus
* -Brief           Called by SW-Cs or BSW modules to report monitor status information to the Dem
* -Details         None
* -Param[in]       EventId: Identification of an event by assigned EventId
* -Param[in]       EventStatus: Monitor test result
* -Return          E_OK: set of event status was successful
*                  E_NOT_OK: Event status setting or processing failed or could not be accepted
*******************************************************************************/
Std_ReturnType Dem_SetEventStatus(
    Dem_EventIdType EventId,
    Dem_EventStatusType EventStatus
)
{
    Dem_DtcInfoType* dtcInfoPtr = (Dem_DtcInfoType*)&Dem_DtcInfo[EventId];
    Dem_EventParameterType* eventParameterConfigPtr = (Dem_EventParameterType*)&Dem_EventParameterConfig[EventId];

    switch(EventStatus)
    {
        case DEM_EVENT_STATUS_PASSED:
        {
            dtcInfoPtr->faultDetCounter = DEM_CFG_COUNTER_PASSED_THRESHOLD(eventParameterConfigPtr);
            break;
        }
        case DEM_EVENT_STATUS_FAILED:
        {
            dtcInfoPtr->faultDetCounter = DEM_CFG_COUNTER_FAILED_THRESHOLD(eventParameterConfigPtr);
            break;
        }
        case DEM_EVENT_STATUS_PREPASSED:
        {
            if(DEM_EVENT_STATUS_PREFAILED == dtcInfoPtr->eventStatusOld)
            {
                if(SET == DEM_CFG_COUNTER_JUMPDOWN(eventParameterConfigPtr))
                {
                    dtcInfoPtr->faultDetCounter = DEM_CFG_COUNTER_JUMPDOWN_VALUE(eventParameterConfigPtr);
                }
            }
            if(dtcInfoPtr->faultDetCounter >=  (DEM_CFG_COUNTER_PASSED_THRESHOLD(eventParameterConfigPtr) + DEM_CFG_COUNTER_DECREMENT_STEP_SIZE(eventParameterConfigPtr)))
            {
                dtcInfoPtr->faultDetCounter = dtcInfoPtr->faultDetCounter - DEM_CFG_COUNTER_DECREMENT_STEP_SIZE(eventParameterConfigPtr);
            }
            else
            {
                dtcInfoPtr->faultDetCounter = DEM_CFG_COUNTER_PASSED_THRESHOLD(eventParameterConfigPtr);
            }
            

            break;
        }
        case DEM_EVENT_STATUS_PREFAILED:
        {
            if(DEM_EVENT_STATUS_PREPASSED == dtcInfoPtr->eventStatusOld)
            {
                if(SET == DEM_CFG_COUNTER_JUMPUP(eventParameterConfigPtr))
                {
                    dtcInfoPtr->faultDetCounter = DEM_CFG_COUNTER_JUMPUP_VALUE(eventParameterConfigPtr);
                }
            }
            if((dtcInfoPtr->faultDetCounter + DEM_CFG_COUNTER_INCREMENT_STEP_SIZE(eventParameterConfigPtr)) <= DEM_CFG_COUNTER_FAILED_THRESHOLD(eventParameterConfigPtr))
            {
                dtcInfoPtr->faultDetCounter = dtcInfoPtr->faultDetCounter + DEM_CFG_COUNTER_INCREMENT_STEP_SIZE(eventParameterConfigPtr);
            }
            else
            {
                dtcInfoPtr->faultDetCounter = DEM_CFG_COUNTER_FAILED_THRESHOLD(eventParameterConfigPtr);
            }
            
            break;

            break;
        }
        case DEM_EVENT_STATUS_FDC_THRESHOLD_REACHED:
        {
            break;
        }
        
        default:
        {
            break;
        }
    }
    if(dtcInfoPtr->faultDetCounter <= DEM_CFG_COUNTER_PASSED_THRESHOLD(eventParameterConfigPtr))
    {
        dtcInfoPtr->monitorStatus |= DEM_MONITOR_STATUS_TF;
    }
    if(dtcInfoPtr->faultDetCounter >= DEM_CFG_COUNTER_FAILED_THRESHOLD(eventParameterConfigPtr))
    {
        dtcInfoPtr->monitorStatus &= (~DEM_MONITOR_STATUS_TF);
    }
    dtcInfoPtr->eventStatusOld = EventStatus;
}

/*******************************************************************************
* -Name            Dem_SetEventStatusWithMonitorData
* -Brief           None
* -Details         None
* -Param[in]       EventId: Identification of an event by assigned EventId
* -Param[in]       EventStatus: Monitor test result
* -Param[in]       monitorData0: Monitor data0
* -Param[in]       monitorData1: Monitor data1
* -Return          E_OK: set of event status was successful
*                  E_NOT_OK: Event status setting or processing failed or could not be accepted
*******************************************************************************/
Std_ReturnType Dem_SetEventStatusWithMonitorData(
    Dem_EventIdType EventId,
    Dem_EventStatusType EventStatus,
    Dem_MonitorDataType monitorData0,
    Dem_MonitorDataType monitorData1
)
{
    
}

/*******************************************************************************
* -Name            Dem_GetDTCStatusAvailabilityMask
* -Brief           Gets the DTC Status availability mask of the selected fault memory
* -Details         None
* -Param[in]       EventId: Identification of an event by assigned EventId
* -Param[in]       DTCOrigin: This parameter selects the event memory the DTCStatus AvailabilityMask is requested for
* -Param[out]      DTCStatusMask: DTCStatusMask The value DTCStatusMask indicates the supported DTC status bits from the Dem.
* -Return          E_OK: get of DTC status mask was successful
*                  E_NOT_OK: get of DTC status mask failed
*******************************************************************************/
Std_ReturnType Dem_GetDTCStatusAvailabilityMask(
    uint8 ClientId,
    Dem_UdsStatusByteType* DTCStatusMask,
    Dem_DTCOriginType DTCOrigin
)
{
    
}


/*******************************************************************************
* -Name            Dem_GetStatusOfDTC
* -Brief           Gets the status of a DTC.
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[out]      DTCStatus: This parameter receives the status information of the requested DTC
* -Return          E_OK: The status of the DTC is correctly provided in the DTCStatus parameter
*                  E_NOT_OK: No DTC selected
*                  DEM_WRONG_DTC: Selected DTC value in selected format does not exist
*                  DEM_WRONG_DTCORIGIN: Selected DTCOrigin does not exist
*                  DEM_PENDING: Retrieving the DTC status is currently in progress. The caller shall 
*                               call this function again at a later moment
*                  DEM_NO_SUCH_ELEMENT: Selected DTC does not have an assigned DTC status.
*                  DEM_BUSY: A different Dem_SelectDTC dependent operation according to SWS_Dem_01253 
*                            of this client is currently in progress
*******************************************************************************/
Std_ReturnType Dem_GetStatusOfDTC(
    uint8 ClientId,
    uint8* DTCStatus
)
{
    Std_ReturnType retVal = E_OK;
    
    Dem_DtcInfoType* dtcInfoPtr = (Dem_DtcInfoType*)&Dem_DtcInfo[ClientId];
    *DTCStatus = dtcInfoPtr->udsStatus;
    
    return(retVal);
}

/*******************************************************************************
* -Name            Dem_SetDTCFilter
* -Brief           Sets the DTC Filter
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[in]       DTCStatusMask: Defines the output-format of the requested DTC values for the sub-sequent API calls
* -Param[in]       DTCOrigin: 
* -Param[in]       FilterWithSeverity: This flag defines whether severity information
* -Param[in]       DTCSeverityMask: Contains the DTCSeverityMask according to ISO14229-1
* -Param[in]       FilterForFaultDetectionCounter: This flag defines whether the fault detection counter information
                                                   shall be used for filtering.
* -Param[out]      DTCStatus: This parameter receives the status information of the requested DTC
* -Return          E_OK: Getting number of filtered DTCs was successful
*                  E_NOT_OK: No DTC filter set
*                  DEM_PENDING: The requested operation is currently in progress
*******************************************************************************/
Std_ReturnType Dem_SetDTCFilter(
    uint8 ClientId,
    uint8 DTCStatusMask,
    Dem_DTCFormatType DTCFormat,
    Dem_DTCOriginType DTCOrigin,
    boolean FilterWithSeverity,
    Dem_DTCSeverityType DTCSeverityMask,
    boolean FilterForFaultDetectionCounter
)
{
    
}

/*******************************************************************************
* -Name            Dem_GetNumberOfFilteredDTC
* -Brief           Gets the number of a filtered DTC
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[out]      NumberOfFilteredDTC: The number of DTCs matching the defined status mask
* -Return          E_OK: Filter was successfully set
*                  E_NOT_OK: Indicates a wrong DTCOrigin or DTCFormat
*******************************************************************************/
Std_ReturnType Dem_GetNumberOfFilteredDTC(
    uint8 ClientId,
    uint16* NumberOfFilteredDTC
)
{
    
}

/*******************************************************************************
* -Name            Dem_GetNextFilteredDTC
* -Brief           Gets the next filtered DTC matching the filter criteria
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[out]      DTC: Receives the DTC value in respective format of the filter
* -Param[out]      DTCStatus: This parameter receives the status information of the requested DTC
* -Return          E_OK: Returned next filtered element
*                  E_NOT_OK: No DTC filter set
*                  DEM_NO_SUCH_ELEMENT: No further element matching the filter criteria found
*                  DEM_PENDING: The requested operation is currently in progress
*******************************************************************************/
Std_ReturnType Dem_GetNextFilteredDTC(
    uint8 ClientId,
    uint32* DTC,
    uint8* DTCStatus
)
{
    
}

/*******************************************************************************
* -Name            Dem_GetNextFilteredDTC
* -Brief           Gets the next filtered DTC and its associated Fault Detection Counter (FDC) matching the filter criteria
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[out]      DTC: Receives the DTC value in respective format of the filter
* -Param[out]      DTCFaultDetectionCounter: This parameter receives the Fault Detection Counter information
* -Return          E_OK: Returned next filtered element
*                  E_NOT_OK: No DTC filter set
*                  DEM_NO_SUCH_ELEMENT: No further element matching the filter criteria found
*                  DEM_PENDING: The requested operation is currently in progress
*******************************************************************************/
Std_ReturnType Dem_GetNextFilteredDTCAndFDC(
    uint8 ClientId,
    uint32* DTC,
    sint8* DTCFaultDetectionCounter
)
{
    
}

/*******************************************************************************
* -Name            Dem_SetDTCFilterByExtendedDataRecordNumber
* -Brief           Sets the DTC Filter based on a given extended data record on the primary fault memory
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[in]       DTCFormat: Defines the DTC format of the requested data.
* -Param[in]       ExtendedDataRecordNumber: hex extended data record number the filter is set for
* -Return          E_OK: Returned next filtered element
*                  E_NOT_OK: No DTC filter set
*                  DEM_NO_SUCH_ELEMENT: No further element matching the filter criteria found
*                  DEM_PENDING: The requested operation is currently in progress
*******************************************************************************/
Std_ReturnType Dem_SetDTCFilterByExtendedDataRecordNumber(
    uint8 ClientId,
    Dem_DTCFormatType DTCFormat,
    uint8 ExtendedDataRecordNumber
)
{
    
}

/*******************************************************************************
* -Name            Dem_DisableDTCRecordUpdate
* -Brief           Disables the event memory update of a specific DTC (only one at one time)
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Return          E_OK: Event memory update successfully disabled
*                  E_NOT_OK: No DTC selected
*                  DEM_WRONG_DTC: Selected DTC value in selected format does not exist or a group of DTC was selected
*                  DEM_WRONG_DTCORIGIN: Selected DTCOrigin does not exist
*                  DEM_PENDING: Disabling the DTC record update is currently in progress
*                  DEM_BUSY: A different Dem_SelectDTC dependent operation in progress
*******************************************************************************/
Std_ReturnType Dem_DisableDTCRecordUpdate(
    uint8 ClientId
)
{
    
}

/*******************************************************************************
* -Name            Dem_EnableDTCRecordUpdate
* -Brief           Enables the event memory update
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Return          E_OK: Event memory update successfully disabled
*                  E_NOT_OK: No DTC selected
*******************************************************************************/
Std_ReturnType Dem_EnableDTCRecordUpdate(
    uint8 ClientId
)
{
    
}

/*******************************************************************************
* -Name            Dem_GetSizeOfExtendedDataRecordSelection
* -Brief           Gets the next filtered DTC and its associated Fault Detection Counter (FDC) matching the filter criteria
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[out]      SizeOfExtendedDataRecord: Size of the requested extended data record(s) including record number
* -Return          E_OK: Size returned successfully
*                  E_NOT_OK: selection function is not called
*                  DEM_PENDING: The requested value is calculated asynchronously and currently not available
*                  DEM_WRONG_DTC: DTC value not existing
*                  DEM_WRONG_DTCORIGIN: Wrong DTC origin
*                  DEM_NO_SUCH_ELEMENT: Record number is not supported by configuration and therefore invalid
*******************************************************************************/
Std_ReturnType Dem_GetSizeOfExtendedDataRecordSelection(
    uint8 ClientId,
    uint32* SizeOfExtendedDataRecord
)
{
    
}

/*******************************************************************************
* -Name            Dem_GetSizeOfFreezeFrameSelection
* -Brief           Gets the size of freeze frame data by DTC selected by the call of Dem_SelectFreezeFrame data
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[out]      SizeOfFreezeFrame: Number of bytes in the requested freeze frame record
* -Return          E_OK: Size returned successfully
*                  E_NOT_OK: selection function is not called
*                  DEM_PENDING: The requested value is calculated asynchronously and currently not available
*                  DEM_WRONG_DTC: DTC value not existing
*                  DEM_WRONG_DTCORIGIN: Wrong DTC origin
*                  DEM_NO_SUCH_ELEMENT: Record number is not supported by configuration and therefore invalid
*******************************************************************************/
Std_ReturnType Dem_GetSizeOfFreezeFrameSelection(
    uint8 ClientId,
    uint32* SizeOfFreezeFrame
)
{
    
}

/*******************************************************************************
* -Name            Dem_GetNextExtendedDataRecord
* -Brief           Gets extended data record for the DTC selected by Dem_SelectExtendedDataRecord
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[inout]    BufSize: When the function is called this parameter contains the maximum number of data bytes that can be written to the buffer
* -Param[out]      DestBuffer: This parameter contains a byte pointer that points to the buffer
* -Return          E_OK: Size and buffer successfully returned
*                  E_NOT_OK: selection function is not called
*                  DEM_BUFFER_TOO_SMALL: provided buffer size too small
*                  DEM_PENDING: The requested value is calculated asynchronously and currently not available. The caller can retry later
*                  DEM_WRONG_DTC: DTC value not existing
*                  DEM_WRONG_DTCORIGIN: Wrong DTC origin
*                  DEM_NO_SUCH_ELEMENT: Found no (further) element matching the filter criteria
*******************************************************************************/
Std_ReturnType Dem_GetNextExtendedDataRecord(
    uint8 ClientId,
    uint8* DestBuffer,
    uint16* BufSize
)
{
    
}

/*******************************************************************************
* -Name            Dem_GetNextFreezeFrameData
* -Brief           Gets freeze frame data by the DTC selected by Dem_SelectFreezeFrameData
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[inout]    BufSize: When the function is called this parameter contains the maximum number of data bytes that can be written to the buffer
* -Param[out]      DestBuffer: This parameter contains a byte pointer that points to the buffer
* -Return          E_OK: Size and buffer successfully returned
*                  E_NOT_OK: selection function is not called
*                  DEM_BUFFER_TOO_SMALL: provided buffer size too small
*                  DEM_PENDING: The requested value is calculated asynchronously and currently not available. The caller can retry later
*                  DEM_WRONG_DTC: DTC value not existing
*                  DEM_WRONG_DTCORIGIN: Wrong DTC origin
*                  DEM_NO_SUCH_ELEMENT: Found no (further) element matching the filter criteria
*******************************************************************************/
Std_ReturnType Dem_GetNextFreezeFrameData(
    uint8 ClientId,
    uint8* DestBuffer,
    uint16* BufSize
)
{
    
}

/*******************************************************************************
* -Name            Dem_SelectExtendedDataRecord
* -Brief           Sets the filter to be used by Dem_GetNextExtendedDataRecord and Dem_GetSizeOfExtended DataRecordSelection
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[in]       ExtendedDataNumber: Identification/Number of requested extended data record
* -Return          E_OK: Extended data record successfully selected
*                  DEM_WRONG_DTC: Selected DTC value in selected format does not exist
*                  DEM_WRONG_DTCORIGIN: Selected DTCOrigin does not exist
*                  DEM_PENDING: Selecting the extended data record is currently in progress
*                  DEM_BUSY: A different Dem_SelectDTC dependent operation in progress
*******************************************************************************/
Std_ReturnType Dem_SelectExtendedDataRecord(
    uint8 ClientId,
    uint8 ExtendedDataNumber
)
{
    
}

/*******************************************************************************
* -Name            Dem_SelectFreezeFrameData
* -Brief           Sets the filter to be used by Dem_GetNextFreezeFrameData and Dem_GetSizeOfFreezeFrame Selection
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[in]       RecordNumber: Unique identifier for a snapshot record as defined in ISO 14229-1
* -Return          E_OK: Extended data record successfully selected
*                  DEM_WRONG_DTC: Selected DTC value in selected format does not exist
*                  DEM_WRONG_DTCORIGIN: Selected DTCOrigin does not exist
*                  DEM_PENDING: Selecting the extended data record is currently in progress
*                  DEM_BUSY: A different Dem_SelectDTC dependent operation in progress
*******************************************************************************/
Std_ReturnType Dem_SelectFreezeFrameData(
    uint8 ClientId,
    uint8 RecordNumber
)
{
    
}

/*******************************************************************************
* -Name            Dem_GetNumberOfFreezeFrameRecords
* -Brief           This function returns the number of all freeze frame records currently stored in the primary event memory
* -Details         None
* -Param[in]       ClientId: Unique client id, assigned to the instance of the calling module
* -Param[out]      NumberOfFilteredRecords: Number of all freeze frame records currently stored in the primary event memory
* -Return          E_OK: Returned correctly the number of freeze frame records
*                  DEM_PENDING: The requested value is calculated asynchronously and currently not available. The caller can retry later
*******************************************************************************/
Std_ReturnType Dem_GetNumberOfFreezeFrameRecords(
    uint8 ClientId,
    uint16* NumberOfFilteredRecords
)
{
    
}

/*******************************************************************************
* -Name            Dem_MainFunction
* -Brief           Processes all not event based Dem internal functions
* -Details         None
* -Return          None
*******************************************************************************/
void Dem_MainFunction(
    void
)
{
    Dem_EventIdType eventId;
    Dem_DtcInfoType* dtcInfoPtr;
    Dem_EventParameterType* eventParameterConfigPtr;

    for(eventId = 0u; eventId < DemConf_DemEventId_Max; eventId++)
    {
        dtcInfoPtr = (Dem_DtcInfoType*)&Dem_DtcInfo[eventId];
        eventParameterConfigPtr = (Dem_EventParameterType*)&Dem_EventParameterConfig[eventId];
        
        if(dtcInfoPtr->faultDetCounter <= DEM_CFG_COUNTER_PASSED_THRESHOLD(eventParameterConfigPtr))
        {
            dtcInfoPtr->udsStatus |= DEM_UDS_STATUS_TF;
            dtcInfoPtr->udsStatus |= DEM_UDS_STATUS_TFTOC;
        }
        if(dtcInfoPtr->faultDetCounter >= DEM_CFG_COUNTER_FAILED_THRESHOLD(eventParameterConfigPtr))
        {
            dtcInfoPtr->udsStatus &= (~DEM_UDS_STATUS_TF);
        }
    }
}


